//
//  ViewController.m
//  03_UIResponder
//
//  Created by dllo on 16/7/18.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor yellowColor];
    TouchView *touch = [[TouchView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    touch.backgroundColor = [UIColor brownColor];
    [self.view addSubview:touch];
    
    // 传进来一个点判断是否你响应
    BOOL isInside = [touch pointInside:CGPointMake(10, 210) withEvent:nil];
    // 比较布尔值用三木运算符
    // 210 > 200 超过边界返回否
    // 所以当响应者出了边界后会导致无法响应的情况
    NSLog(@"%d",isInside ? YES : NO);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(50, 150, 80, 80);
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"哈喽" forState:0];
    [touch addSubview:button];
    [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    
#pragma mark -  - (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;   // recursively calls -pointInside:withEvent:. point is in the receiver's coordinate system
#pragma mark    - (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event;   // default returns YES if point is in bounds
    // 以上两种方法会使得出边界的能响应,(一半在里面一半在外边,或者全在外边)
//    - (CGPoint)convertPoint:(CGPoint)point toView:(nullable UIView *)view;
//    - (CGPoint)convertPoint:(CGPoint)point fromView:(nullable UIView *)view;
//    - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
//    - (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;
    // 以上六个方法能解决很多事
    // UIImageView 和UILabel的默认响应是关闭的,所以需要时候需要打开
    
}
- (void)click {
    NSLog(@"你好");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    //
    NSLog(@"\n%s------%@",__FUNCTION__,NSStringFromClass([self class]));
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
